﻿app.controller("ngEditPostController", function ($scope, $http, $location, $routeParams) {
    $scope.formPost;
    $scope.isEdit = true;

    $http.get("/api/post/" + $routeParams.id).success(function (data) {
        $scope.formPost = data.Post;
    }).error(function (data) {
        console.log(JSON.stringify(data));
    })

    $scope.savePost = function (post) {
        $http.put("/api/post", post).success(function (data) {
            $location.path("/PostDetail/" + data.Id);
        }).error(function (data) {
            console.log(JSON.stringify(data));
        });
    }

    $scope.deletePost = function (post) {
        $http.delete("api/post/" + post.Id).success(function () {
            $location.path("/");
        }).error(function (data) {
            console.log(JSON.stringify(data));
        });
    }

    $scope.cancel = function () { $location.path("/PostDetail/" + $routeParams.Id); };

});